<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>

<script type="text/javascript" src="js/jquery.itextclear.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $('input[type=text], input[type=password], input[type=url], input[type=email], input[type=number], textarea', '.form').iTextClear();
    });
</script>
<!-- jQplot CSS -->

<link rel="stylesheet" media="screen" href="CSS/Tree.css"/>
<!-- jQplot CSS END -->

<!-- DATATABLES CSS -->
<link rel="stylesheet" media="screen" href="lib/datatables/css/vpad.css"/>
<script type="text/javascript" src="lib/datatables/js/jquery.dataTables.js"></script>

<!-- DATATABLES CSS END -->

<h1 class="page-title">薪资扣款区间 - ${title}</h1>

<div class="container_12 clearfix leading">


    <div class="side grid_12 leading">
        <form class="form has-validation" id="post_form" name="post_form">


            <div class="clear"></div>
            <s:if test="#request.salaryIndividualTaxRule.id>0">
                <input type="hidden" name="salaryIndividualTaxRule.id" value="${salaryIndividualTaxRule.id}"/>
            </s:if>
            <input type="hidden" name="salaryIndividualTaxRule.organization.id"
                   value="${salaryIndividualTaxRule.organization.id}"/>

            <div class="clearfix">

                <label for="remark" class="form-label">薪资扣款区间 <em>*</em></label>

                <div class="form-input">
                    <input name="salaryIndividualTaxRule.amountEnd" value="${salaryIndividualTaxRule.amountEnd}"
                           type="text" required="required" id="amountEnd"
                           placeholder="请输扣款上标，-1表示无穷大"/>

                    <input name="salaryIndividualTaxRule.amountStart" value="${salaryIndividualTaxRule.amountStart}"
                           type="text" required="required" id="amountStart" placeholder="请输扣款下标"/>
                </div>

            </div>

			<div class="clearfix">

                <label for="fastCutValue" class="form-label">税率 <em>*</em></label>

                <div class="form-input">
                    <input name="salaryIndividualTaxRule.taxRate" value="${salaryIndividualTaxRule.taxRate}"
                           type="text" required="required" id="taxRate" placeholder="请输入税率百分比"/>
                </div>

            </div>
            <div class="clearfix">

                <label for="fastCutValue" class="form-label">速扣值 <em>*</em></label>

                <div class="form-input">
                    <input name="salaryIndividualTaxRule.fastCutValue" value="${salaryIndividualTaxRule.fastCutValue}"
                           type="text" required="required" id="fastCutValue" placeholder="请输入速扣值"/>
                </div>

            </div>
            <div class="clearfix">

                <label class="form-label" for="remark">备注</label>

                <div class="form-input form-textarea"><span class="iTextClearButtonContainer"><textarea placeholder="备注"
                                                                                                        rows="5"
                                                                                                        id="remark"
                                                                                                        name="salaryIndividualTaxRule.remark">${salaryIndividualTaxRule.remark}</textarea><a
                        class="iTextClearButton" style="display: none;"></a></span></div>

            </div>


            <div class="form-action clearfix">

                <button class="button" type="button" onclick="checkForm();">${title}</button>

                <button class="button" type="reset">重置</button>
                <a class="button" href="#salary/individual_tax_rule_main.xhtml"><span
                        style="background:url(${ctx}/images/img/arrow_undo.png)" class="icon">&nbsp;</span>返回</a>

            </div>

        </form>
    </div>
</div>

<div class="clear"></div>


<script type="text/javascript">
    function checkForm() {

        if ($("#amountStart").val() == null
                || $("#amountStart").val().trim() == ""
                || isNaN($("#amountStart").val())
                || parseFloat($("#amountStart").val().trim()) < 0) {
            alert("请输入有效的扣款上标值");
            return;
        }
        if ($("#amountEnd").val() == null || $("#amountEnd").val().trim() == ""
                || isNaN($("#amountEnd").val())
                || parseFloat($("#amountEnd").val().trim()) < 0 && parseFloat($("#amountEnd").val().trim()) != -1) {
            alert("请输入有效的扣款下标值");
            return;
        }

        if(parseFloat($("#amountEnd").val().trim()) != -1 && parseFloat($("#amountStart").val().trim()) >= parseFloat($("#amountEnd").val().trim())) {
            alert("薪资扣款区间设定异常，下限不能大于上限,请重新输入");
            return;
        }

        if ($("#taxRate").val() == null || $("#taxRate").val().trim() == ""
            || isNaN($("#taxRate").val()) || parseFloat($("#taxRate").val().trim()) < 0 ||  parseFloat($("#taxRate").val().trim())> 100) {
	        alert("请填写有效的税率百分比值");
	        return;
	    }
        
        
        if ($("#fastCutValue").val() == null || $("#fastCutValue").val().trim() == ""
                || isNaN($("#fastCutValue").val())) {
            alert("请填写有效的速扣值");
            return;
        }

        //检测数据有效性
    <%--var url = "${ctx}/exam/validate_standscore.xhtml";--%>
    <%--var availability = true;--%>
    <%--$.ajax(url,--%>
    <%--{--%>
    <%--type : "POST",--%>
    <%--async:false,--%>
    <%--data : {"organizationId":eval("${examQualStandardSet.organization.id}"),--%>
    <%--"st":parseFloat($("#scoreStart").val().trim()),--%>
    <%--"se":parseFloat($("#scoreEnd").val().trim()),--%>
    <%--"i":eval("${examQualStandardSet.id}")},--%>
    <%--dataType : "html",--%>
    <%--cache : false,--%>
    <%--success : function(data) {--%>
    <%--if(data != null){--%>
    <%--var validate = eval("(" + data + ")");--%>
    <%--if(!validate.availability){--%>
    <%--availability = false;--%>
    <%--}--%>
    <%--}--%>
    <%--},--%>
    <%--error : function(XMLHttpRequest, textStatus,--%>
    <%--errorThrown) {--%>
    <%--alert('检测数据异常');--%>
    <%--},--%>
    <%--complete : function() {--%>
    <%--}--%>
    <%--});--%>
    <%--if(!availability){--%>
    <%--alert("输入的分数区间已经存在，请重新输入");--%>
    <%--return;--%>
    <%--}--%>

        var url = "${ctx}/salary/individual_tax_rule_save.xhtml";
        $.ajax(
                url,
        {
            type : "POST",
            data : $("#post_form").serialize(),
            dataType : "html",
            cache : false,
            success : function(a) {
                return pageDownloaded(a, url);
            },
            error : function(XMLHttpRequest, textStatus,
                             errorThrown) {
                alert('提交申请发生异常');
            },
            complete : function() {
            }
        });
    }
</script>
    